package org.example.his.common.error;


import org.example.his.common.api.CommonResponse;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionTranslator {
    @ExceptionHandler(MissingServletRequestParameterException.class)
    public CommonResponse handleError(MissingServletRequestParameterException e) {
        //记录日志

        String message = String.format("没有传递请求参数:%s", e.getParameterName());
        return CommonResponse.createForError(message);
    }

    @ExceptionHandler(ServiceException.class)
    public CommonResponse handleError(ServiceException e) {
        return CommonResponse.createForError(e.getMessage());
    }
}
